package com.talkyun.utils.reflect;

public class BoolUtils {

    public static Boolean getBoolValue(Object value, Class<?> clazz) {
        if (value instanceof Boolean) {
            return (Boolean) value;
        } else if (value.getClass() == boolean.class) {
            return (boolean) value;
        }

        String text = value.toString().trim();
        if ("true".equalsIgnoreCase(text)) {
            return Boolean.TRUE;
        } else if ("false".equalsIgnoreCase(text)) {
            return Boolean.FALSE;
        } else if ("y".equalsIgnoreCase(text)) {
            return Boolean.TRUE;
        } else if ("n".equalsIgnoreCase(text)) {
            return Boolean.FALSE;
        } else if ("1".equals(text)) {
            return Boolean.TRUE;
        } else if ("0".equals(text)) {
            return Boolean.FALSE;
        }

        throw new RuntimeException("Unknown boolean string! " + text);
    }

}
